<template>
	<view class="driverlist">
		<view class="userInfo">
			<image class="" src="@/static/image/driver.png" style="width: 120rpx;height: 120rpx;" />
			<view class="name">
				<view class="">
					司机
				</view>
				<view class="">
					{{userInfo.name}}
				</view>
			</view>
		</view>

		<view class="tabsBox">
			<view class="title">
				我的订单
			</view>
			<view class="tabsitem">
				<view class="item" @click="handleTabs(1)">
					<image v-if="currIndex == 1" class="" src="@/static/image/dsd.png"
						style="width: 72rpx;height: 72rpx;" />
					<image v-else class="" src="@/static/image/dsded.png" style="width: 72rpx;height: 72rpx;" />
					<view class="" :class="{colered: currIndex == 1}">
						待送单
					</view>
				</view>
				<view class="item" @click="handleTabs(2)">
					<image v-if="currIndex == 2" class="" src="@/static/image/ysded.png"
						style="width: 72rpx;height: 72rpx;" />
					<image v-else class="" src="@/static/image/ysd.png" style="width: 72rpx;height: 72rpx;" />
					<view class="" :class="{colered: currIndex == 2}">
						已送单
					</view>
				</view>
			</view>
		</view>
		<view v-if="currIndex == 1" class="dataList">

			<view v-if="deliveredListL.length>0" class="dataBox">
				<view class="dataitem" v-for="(item,index) in deliveredListL">
					<view class="top">
						<view class="number">
							订单编号 {{item.out_trade_no}}
						</view>
						<view class="config" @click="handleConfigShow(item.id)">
							确认送单
						</view>
					</view>
					<view class="dataSubitem">
						<view class="info">
							<view class="avatar">
								<image class="" src="@/static/image/driver.png"
									style="width: 45.55rpx;height: 45.55rpx;" />
							</view>
							<view class="nikename">
								{{item.name}}
							</view>
						</view>

						<view class="message">
							<view class="name">
								{{item.good.name}}
							</view>
							<view class="shuliang">
								<!-- {{subitem.good_info.capacity}}L -->
							</view>
						</view>
						<view class="sumandnum">
							<view class="sum">
								￥{{item.good.price}}
							</view>
							<view class="num" style="color: #A7A7A7;">
								x{{item.count}}
							</view>
						</view>

					</view>

					<view class="dfk">
						手机号：{{item.mobile}}
					</view>
					<view class="dfk">
						收货地址：{{item.town}}{{item.village}}
					</view>
				</view>

			</view>

			<view v-else class="">
				<u-empty text="暂无订单" icon="http://cdn.uviewui.com/uview/empty/order.png">
				</u-empty> 
			</view>

		</view>


		<view v-if="currIndex == 2" class="dataList">

			<view v-if="deliveredListL.length>0" class="dataBox">
				<view class="dataitem" v-for="(item,index) in deliveredListL">
					<view class="top">
						<view class="number">
							订单编号 {{item.out_trade_no}}
						</view>

						<view class="config" @click="handlecompleteshow(item.id)">
							送单完成
						</view>
					</view>
					<view class="dataSubitem">
						<view class="info">
							<view class="avatar">
								<image class="" src="@/static/image/driver.png"
									style="width: 45.55rpx;height: 45.55rpx;" />
							</view>
							<view class="nikename">
								{{item.name}}
							</view>
						</view>

						<view class="message">
							<view class="name">
								{{item.good.name}}
							</view>
							<view class="shuliang">
								<!-- {{subitem.good_info.capacity}}L -->
							</view>
						</view>
						<view class="sumandnum">
							<view class="sum">
								￥{{item.good.price}}
							</view>
							<view class="num" style="color: #A7A7A7;">
								x{{item.count}}
							</view>
						</view>

					</view>

					<view class="dfk">
						手机号：{{item.mobile}}
					</view>
					<view class="dfk">
						收货地址：{{item.town}}{{item.village}}
					</view>

				</view>
			</view>

			<view v-else class="">
				<u-empty text="暂无订单" icon="http://cdn.uviewui.com/uview/empty/order.png">
				</u-empty>
			</view>

		</view>

		<view class="" style="height: 100rpx;"></view>

		<u-popup :show="show" mode="center" :round="30">
			<view class="subAddress">
				<view class="title">
					确认送单
				</view>
				<view class="content">
					您确定开始送单吗？
				</view>
				<view class="bottomBtn">
					<view class="btnleft" @click="show = false">
						取消
					</view>
					<view class="btnright" @click="handleUpdatestatus">
						确认
					</view>
				</view>
			</view>
		</u-popup>

		<u-popup :show="completeshow" mode="center" :round="30">
			<view class="subAddress">
				<view class="title">
					送单完成
				</view>
				<view class="content">
					您确定已完成送单了吗？
				</view>
				<view class="bottomBtn">
					<view class="btnleft" @click="completeshow = false">
						取消
					</view>
					<view class="btnright" @click="handleUpdatestatus">
						确认
					</view>
				</view>
			</view>
		</u-popup>



	</view>
</template>

<script>
	import {
		userInfo,
		driverOrderlist,
		driverUpdatestatus
	} from "@/api/api.js"
	export default {
		data() {
			return {
				currIndex: 1,
				userInfo: {},
				show: false,
				pageSize: 10,
				page: 1,
				status: 1, //1待送单   2已送单 
				deliveredListL: [], //待送单
				sentOrderList: [], //已送单
				orderId: null, //订单id
				completeshow: false,
			}
		},
		onLoad() {
			// this.getuUserInfo()
			// this.getDriverOrderlist()
		},
		onShow() {
			this.getuUserInfo()
			this.getDriverOrderlist()
		},
		onReachBottom() {
			this.page = this.page + 1;
			this.getDriverOrderlist();
		},
		methods: {

			async getDriverOrderlist() {
				let data = {
					page_size: this.pageSize,
					page: this.page,
					status: this.status
				}
				let res = await driverOrderlist(data)
				if (res.code == 1000) {
					// this.deliveredListL = res.data.data
					if (res.data.data.length == 0) {
						uni.showToast({
							title: "暂无更多订单！",
							icon: "none",
							duration: 1000
						});
						return
					}
					res.data.data.forEach((item, index) => {
						this.deliveredListL.push(item)
					})
					// console.log("3333333",this.deliveredListL)
				}
				console.log("司机订单", res)
			},
			handleConfigShow(id) {
				this.show = true
				this.orderId = id
				console.log("id", id)
			},
			handlecompleteshow(id) {
				this.completeshow = true
				this.orderId = id
			},
			async handleUpdatestatus() {
				let res = await driverUpdatestatus({
					id: this.orderId
				})
				if (res.code == 1000) {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 1000
					});
					this.show = false
					this.completeshow = false
					this.page = 1
					this.deliveredListL = []
					this.getDriverOrderlist()
				} else {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 1000
					});
				}
				console.log("修改状态", res)
			},
			async getuUserInfo() {
				let res = await userInfo()
				this.userInfo = res.data
				// console.log("司机信息", res.data)
			},
			handleTabs(index) {
				this.page = 1
				this.deliveredListL = []
				this.currIndex = index
				this.status = index
				this.getDriverOrderlist()
			}
		}
	}
</script>

<style scoped lang="scss">
	.subAddress {
		width: 686rpx;
		// height: 500rpx;
		background: #FFFFFF;
		// box-shadow: 0rpx 8rpx 52rpx 0rpx rgba(0, 0, 0, 0.12);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 90rpx 30rpx;
		box-sizing: border-box;

		.title {
			font-size: 50rpx;
			font-family: PingFang SC-Semibold, PingFang SC;
			font-weight: 600;
			color: #000000;
			line-height: 50rpx;
			text-align: center;
		}

		.content {
			margin-top: 50rpx;
			font-size: 50rpx;
			font-family: PingFang SC-Semibold, PingFang SC;
			font-weight: 600;
			color: #000000;
			line-height: 50rpx;
			text-align: center;
		}

		.bottomBtn {
			display: flex;
			justify-content: space-between;
			margin-top: 84rpx;

			.btnleft {
				width: 184rpx;
				height: 88rpx;
				background: #A7A7A7;
				border-radius: 60rpx 60rpx 60rpx 60rpx;
				font-size: 48rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				line-height: 50rpx;
				text-align: center;
				line-height: 88rpx;
			}

			.btnright {
				width: 406rpx;
				height: 88rpx;
				background: linear-gradient(180deg, #FE5C5C 0%, rgba(255, 78, 78, 0.67) 100%);
				border-radius: 60rpx 60rpx 60rpx 60rpx;
				font-size: 48rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				line-height: 50rpx;
				text-align: center;
				line-height: 88rpx;
			}
		}
	}

	.driverlist {
		.userInfo {
			width: 100%;
			padding: 30rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;

			.name {
				font-size: 40rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #000000;
				line-height: 50rpx;
				margin-left: 16rpx;
			}
		}

		.tabsBox {
			width: 702rpx;
			height: 250rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 8rpx 2rpx rgba(0, 0, 0, 0.05);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin: 32rpx auto;
			padding: 16rpx;
			box-sizing: border-box;

			.title {
				font-size: 32rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #000000;
				line-height: 50rpx;
			}

			.tabsitem {
				display: flex;
				justify-content: space-around;
				margin-top: 30rpx;

				.item {
					text-align: center;
				}
			}

			.colered {
				color: #FF4E4E;
			}

		}

		.dataList {
			width: 702rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 16rpx 24rpx;
			box-sizing: border-box;
			margin: 0 auto;

			.top {
				display: flex;
				justify-content: space-between;

				.number {
					font-size: 24rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
					color: #000000;
					line-height: 50rpx;
				}

				.config {
					width: 170rpx;
					height: 70rpx;
					background: #FF4E4E;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					color: #ffffff;
					line-height: 70rpx;
					text-align: center;
					font-size: 30rpx;
				}

			}

			.dataBox {
				margin-top: 16rpx;

				.dataitem {
					width: 100%;
					background: #FFFFFF;
					box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					padding: 16rpx 24rpx;
					box-sizing: border-box;
					margin-bottom: 20rpx;

					.dataSubitem {
						display: flex;
						justify-content: space-between;
						margin-top: 20rpx;

						.info {
							display: flex;
							font-size: 28rpx;
							font-family: PingFang SC-Semibold, PingFang SC;
							font-weight: 600;
							color: #000000;
							line-height: 50rpx;
						}

						.message {
							.name {
								width: 320rpx;
								height: 50rpx;
								font-size: 24rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #000000;
								line-height: 50rpx;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
							}

							.shuliang {
								font-size: 24rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #A7A7A7;
								line-height: 50rpx;
							}

						}

						.sumandnum {
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #000000;
							line-height: 50rpx;
							text-align: right;
						}
					}

					.dfk {
						font-size: 25rpx;
						font-family: PingFang SC-Semibold, PingFang SC;
						font-weight: 600;
						color: #000000;
						line-height: 50rpx;
						// text-align: right;
					}
				}

			}
		}
	}
</style>